package com.linkage.jz.bankruptcy.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;

import com.linkage.jz.bankruptcy.R;

public class ApplyBaseReplyDialog extends Dialog {

    /**
     * 上下文对象 *
     */
    Activity context;

    public CheckBox cb_pass, cb_nopass, send_msg, send_phone;
    private Button btn_save, btn_chancel;

    public EditText text_reason;


    private View.OnClickListener mClickListener;

    public ApplyBaseReplyDialog(Activity context) {
        super(context);
        this.context = context;
    }

    public ApplyBaseReplyDialog(Activity context, View.OnClickListener clickListener) {
        super(context);
        this.context = context;
        this.mClickListener = clickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 指定布局
        this.setContentView(R.layout.apply_baseuser_dialog);


        cb_pass = (CheckBox) findViewById(R.id.cb_pass);
        cb_nopass = (CheckBox) findViewById(R.id.cb_nopass);
        send_msg = (CheckBox) findViewById(R.id.send_msg);
        send_phone = (CheckBox) findViewById(R.id.send_phone);

        send_msg.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (!isChecked) {

                    send_msg.setChecked(true);
                }

            }
        });
        cb_pass.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (!isChecked && !cb_nopass.isChecked()) {
                    text_reason.setVisibility(View.GONE);
                    cb_pass.setChecked(true);
                }
                if (isChecked) {
                    text_reason.setVisibility(View.GONE);
                    cb_nopass.setChecked(false);
                }
            }
        });
        text_reason = (EditText) findViewById(R.id.text_reason);


        cb_nopass.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                if (!isChecked && !cb_pass.isChecked()) {
                    text_reason.setVisibility(View.VISIBLE);
                    cb_nopass.setChecked(true);
                }
                if (isChecked) {
                    text_reason.setVisibility(View.VISIBLE);
                    cb_pass.setChecked(false);
                }
            }
        });


        /*
         * 获取圣诞框的窗口对象及参数对象以修改对话框的布局设置, 可以直接调用getWindow(),表示获得这个Activity的Window
         * 对象,这样这可以以同样的方式改变这个Activity的属性.
         */
        Window dialogWindow = this.getWindow();

        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        // p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.6
        p.width = (int) (d.getWidth() * 0.9); // 宽度设置为屏幕的0.8
        dialogWindow.setAttributes(p);

        // 根据id在布局中找到控件对象
        btn_save = (Button) findViewById(R.id.btn_save);

        btn_chancel = (Button) findViewById(R.id.btn_chancel);
        // 为按钮绑定点击事件监听器
        btn_save.setOnClickListener(mClickListener);
        btn_chancel.setOnClickListener(mClickListener);

        this.setCancelable(true);
    }
}


